//
//  IncidentCell.m
//  Runone
//
//  Created by runone02 on 16/8/27.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "IncidentCell.h"


@implementation IncidentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

+ (instancetype)incidentCell
{
    return [[[NSBundle mainBundle] loadNibNamed:@"incidentCell" owner:nil options:nil] firstObject];
}
- (void)setCellData:(CurrentEvent *)data {
    //事件
    if (data.IncidentType  == 1) {
        self.firstLabel.text  = @"事故事件";
    }else if(data.IncidentType == 3) {
        self.firstLabel.text  = @"施工事件";
    }
    //方向
    NSInteger derection = [data.RoadDerection integerValue];
    if (derection == 1) {
        self.secondLabel.text = @"往广州方向";
    }else {
        self.secondLabel.text = @"往湖南方向";
    }
    
    if (data.DealDetail == nil) {
        self.thirdLabel.hidden = YES;
    }else {
   self.thirdLabel.text  = [NSString stringWithFormat:@"%@",data.DealDetail];
}
    self.timeLabel.text   = [NSString stringWithFormat:@"时间：%@",data.RecordTime];
    self.stakeLabel.text  = [NSString stringWithFormat:@"%@+%@",data.BeginPile,data.BeginPileDistance];
    //图片
    if (data.IncidentType == 1) {
        self.iconView.image = [UIImage imageNamed:@"事故"];
    }else {
        self.iconView.image = [UIImage imageNamed:@"施工"];
    }
    self.EventStateLabel.hidden =YES;
}

- (void)setCellTollData:(TollEvent *)tollData {
    NSString *firstStr = nil;
    if (tollData.EventType == 1) {
        firstStr = @"逃费事件";
    }else if(tollData.EventType == 2){
    firstStr = @"冲卡事件";
    }else if(tollData.EventType == 3){
    firstStr = @"现场纠纷";
    }else {
    firstStr = @"收费事件";
    }
    self.firstLabel.text = firstStr;
    
    self.secondLabel.text = tollData.TollStationName;
    self.thirdLabel.text = tollData.DutyMonitor;
    self.timeLabel.text = tollData.OccurTime;
    //图片
    self.iconView.image = [UIImage imageNamed:@"收费"];
    self.EventStateLabel.hidden = YES;
    self.contentLabel.hidden    = YES;
    self.stakeLabel.hidden      = YES;
}
- (void)setCellReportData:(ReportEvent *)reportedData {
    self.firstLabel.text = [NSString stringWithFormat:@"%@",reportedData.RecordUserName];
    
    if (reportedData.BeginPile == nil) {
        reportedData.BeginPile = @"";
    }else if(reportedData.BeginPileDistance == nil) {
        reportedData.BeginPileDistance= @"";
    }else if (reportedData.BeginPileDistance) {
        reportedData.BeginPile = [NSString stringWithFormat:@"%@+",reportedData.BeginPile];
    }
    self.thirdLabel.text = [NSString stringWithFormat:@"桩号:%@%@",reportedData.BeginPile,reportedData.BeginPileDistance];
    self.stakeLabel.hidden  = YES;
    self.secondLabel.text = [NSString stringWithFormat:@"%@",reportedData.RecordUserOrgName];
    self.iconView.image = [UIImage imageNamed:@"广乐高速-副本-2"];
    self.timeLabel.text   = [NSString stringWithFormat:@"更新时间：%@",reportedData.RecordTime];
#pragma mark - >>>>>>>判断事件状态
    NSDate *today = [NSDate date];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate: today];
    NSDate *localeDate = [today  dateByAddingTimeInterval: interval];
    NSLog(@"%@",localeDate);
    NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *occurData =[dateFormat dateFromString:reportedData.OccurTime];
//    NSDate *endData =[dateFormat dateFromString:reportedData.EndTime];
    NSComparisonResult result1 = [today compare:occurData];
//    NSComparisonResult result2 = [today compare:endData];
    NSString *stateStr = nil;
    if (result1 == NSOrderedAscending) {
        stateStr = @"未开始";
    }else {
         stateStr = @"进行中";
    }
    self.EventStateLabel.text = stateStr;
    
    self.contentLabel.hidden = YES;
}





@end
